﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace thinger.VisionDemo
{
    public partial class FrmReCheck : Form
    {
        private string ErrTxtPath = Application.StartupPath + "\\errtype";

        private List<string> ErrDatas = new List<string>();
        public FrmReCheck()
        {
            InitializeComponent();
            //定时器
            this.updateTimer.Interval = 200;
            this.updateTimer.Tick += UpdateTimer_Tick;
            this.updateTimer.Start();
            //初始化
            this.Load += FrmloadErrTxt;
            this.FormClosing += FrmCloseNow;
            //

        }
        private Timer updateTimer = new Timer();
        private void UpdateTimer_Tick(object sender, EventArgs e)
        {
            txt_duma.Text = GlobalVar.Instance.dumaCoder;
        }
        //关闭
        public void FrmCloseNow(object sender, EventArgs e)
        {
        }



        //启动加载 txt
        public void FrmloadErrTxt(object sender, EventArgs e)
        {
            string path = ErrTxtPath + "\\";


            //如果包含，删除
            if (!Directory.Exists(path))
            {
                //创建文件夹
                Directory.CreateDirectory(path);

            }

            string filePath = path + "err_type.txt";

            if (File.Exists(filePath))
            {
                Console.WriteLine("文件存在。");
            }
            else
            {
                File.WriteAllText(filePath, ""); // 将内容写入文件
            }





            ErrDatas = ReadTextFileToList(filePath);
            if (ErrDatas.Count < 1)
            {
                return;
            }

            for (int i = 0; i < ErrDatas.Count; i++)
            {
                int temp = i + 1;
                string checkboxNanme = "checkBox" + temp;

                if (((CheckBox)this.Controls.Find("checkBox" + temp, true)[0]).Name == checkboxNanme)
                {
                    ((CheckBox)this.Controls.Find("checkBox" + temp, true)[0]).Visible = true;
                    ((CheckBox)this.Controls.Find("checkBox" + temp, true)[0]).Text = ErrDatas[i].ToString();
                }

            }

        }




        //读取文本文件转换为List 

        public List<string> ReadTextFileToList(string fileName)

        {

            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            List<string> list = new List<string>();

            StreamReader sr = new StreamReader(fs);

            //使用StreamReader类来读取文件 

            sr.BaseStream.Seek(0, SeekOrigin.Begin);

            // 从数据流中读取每一行，直到文件的最后一行 

            string tmp = sr.ReadLine();

            while (tmp != null)

            {

                list.Add(tmp);

                tmp = sr.ReadLine();

            }

            //关闭此StreamReader对象 

            sr.Close();

            fs.Close();

            return list;

        }

        private void btnNGResult_Click(object sender, EventArgs e)
        {
            if (checkBox_mes.Checked)
            {
                //发送到mes
            }
            //保存到本地
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBox_mes.Checked)
            {
                //发送到mes
            }
            //保存到本地
        }

        private void btnLastImage_Click(object sender, EventArgs e)
        {
            //上一张
        }

        private void btnNextImage_Click(object sender, EventArgs e)
        {
            //下一张
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string row = "35";
            string col = "46";
            string good = "1522";
            textBox7.Text = "23092801-B-002";
            string str = "Strip_ID：" + textBox7.Text + "\n";
            str += "Manufafacturer P/N：" + textBox8.Text + "\n";
            str += "Customer P/N：" + textBox9.Text + "\n";
            str += "Row = " + row + "；Col = " + col + "\n";
            str += "GOOD UNIT : " + good + "\n\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            str += "1110111111011111110111111111111111111101111111" + "\n";
            MessageBox.Show(str);

            GlobalVar.Instance.WriteTXT_StreamWriter("D:\\2\\mapping\\" + textBox7.Text.Trim() + ".txt", str);
        }
    }
}
